﻿using System.Web;
using System.Collections.Generic;
using GMS.Framework.Common.TopOnline;

namespace GMS.Framework.Utility
{
    /// <summary>
    /// 判断消息内容的合法性
    /// </summary>
    public class JudgeMessageContent
    {
        /// <summary>
        /// 处理消息内容特殊字符和判断是否有关键字
        /// </summary>
        /// <param name="judgeContent">消息内容</param>
        /// <param name="content">处理特殊字符后的消息内容</param>
        /// <param name="containkeyWord">返回 所含有的第一个关键字</param>
        /// <param name="keyWords">敏感词</param>
        /// <returns>true表示没有关键字，false表示含有关键字</returns>
        public static bool JudgeAndDealContent(string judgeContent, out string content, out string containkeyWord,string[] keyWords)
        {
            //过滤关键字
            containkeyWord = "";
            foreach (var keyword in keyWords)
            {
                if (judgeContent.Contains(keyword))
                {
                    containkeyWord = keyword;
                    content = judgeContent;
                    return false;
                }
            }
            //处理特殊字符
            judgeContent = judgeContent.Replace("\r\n", "");
            judgeContent = judgeContent.Replace(",", "，");
            judgeContent = judgeContent.Replace("【", "(");
            judgeContent = judgeContent.Replace("】", ")");
            content = judgeContent;
            return true;
        }
    }
}
